package java0414;

import java.util.Scanner;
import java.util.Stack;

// 牛客:计算糖果
//public class Main {
//    public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        while (scanner.hasNext()) {
//            int[] nums = new int[4];
//            for (int i = 0; i < 4; i++) {
//                nums[i] = scanner.nextInt();
//            }
//            String ret = func(nums);
//            System.out.println(ret);
//        }
//    }
//
//    public static String func(int[] nums) {
//        int[] ret = new int[3];
//        for (ret[0] = -30; ret[0] <= 30; ret[0]++) {
//            for (ret[1] = -30; ret[1] <= 30; ret[1]++) {
//                for (ret[2] = -30; ret[2] <= 30; ret[2]++) {
//                    if (ret[0] - ret[1] == nums[0]
//                            && ret[1] - ret[2] == nums[1]
//                            && ret[0] + ret[1] == nums[2]
//                            && ret[1] + ret[2] == nums[3]) {
//                        return "" + ret[0] + " " + ret[1] + " " + ret[2];
//                    }
//                }
//            }
//        }
//        return "No";
//    }
//}

// 牛客:进制转换
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            long M = scanner.nextLong();
            int N = scanner.nextInt();
            String ret = func(M, N);
            System.out.println(ret);
        }
    }

    public static String func(long M, int N) {
        if (M == 0) {
            return "0";
        }
        char[] table = new char[16];
        for (int i = 0; i <= 9; i++) {
            table[i] = (char)('0' + i);
        }
        table[10] = 'A';
        table[11] = 'B';
        table[12] = 'C';
        table[13] = 'D';
        table[14] = 'E';
        table[15] = 'F';
        Stack<Character> stack = new Stack<>();
        while (M > 0) {
            char now = table[(int)(M % N)];
            stack.push(now);
            M /= N;
        }
        String ret = "";
        while (stack.isEmpty() == false) {
            ret += stack.pop();
        }
        return ret;
    }
}
